package com.fbt.transfer.app.driver.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Comparator;
import lombok.Getter;

/**
 * @author tuocoo
 * @date 2020年05月07日/14:28
 */
@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum OrderStatusEnum implements Comparator<OrderStatusEnum> {
  /** 待支付 */
  UNKNOWN(-1, "未知状态"),
  WAIT_FOR_ASSIGN(1, "待接单"),
  TAKE_ORDER(5, "待服务"),
  CHANGE_OTHER_DRIVER(7, "待服务"),
  GO_TO_START(10, "前往预约点"),
  WAIT_FOR_PASSENGER(15, "已就位"),
  ON_CAR(20, "行程中"),
  FINISHED(25, "已完成"),
  COMMENTED(50, "已评论"),
  PASSENGERS_CANCEL(120, "用户取消"),
  CUSTOMER_SERVICE_CANCEL(121, "客服取消"),
  THIRD_CUSTOMER_SERVICE_CANCEL(122, "客服取消"),
  DRIVER_CANCEL(126, "司机取消"),
  FLIGHT_CANCEL(127, "航班取消"),
  ;
  private final Integer value;
  private final String desc;

  OrderStatusEnum(int value, String desc) {
    this.value = value;
    this.desc = desc;
  }

  public static OrderStatusEnum getByValue(Integer value) {
    for (OrderStatusEnum orderStatusEnum : values()) {
      if (orderStatusEnum.getValue().equals(value)) {
        return orderStatusEnum;
      }
    }
    return UNKNOWN;
  }

  @Override
  public int compare(OrderStatusEnum o1, OrderStatusEnum o2) {
    return o1.getValue().compareTo(o2.getValue());
  }

  public  boolean isFinished() {
    return FINISHED==this || COMMENTED == this;
  }

  public  boolean isCancel() {
    return PASSENGERS_CANCEL == this
        || CUSTOMER_SERVICE_CANCEL == this
        || THIRD_CUSTOMER_SERVICE_CANCEL == this
        || DRIVER_CANCEL == this
        || FLIGHT_CANCEL == this;
  }

  /** 是否在服务中 */
  public  boolean isInService() {
    return GO_TO_START == this || WAIT_FOR_PASSENGER == this || ON_CAR == this;
  }

  /** 是否已接单 */
  public  boolean isTakeOrder() {
    return TAKE_ORDER == this || CHANGE_OTHER_DRIVER == this;
  }
}
